package com.ztt.service.impl;

import com.ztt.pojo.entity.zttSupplier;
import com.ztt.mapper.SupplierMapper;
import com.ztt.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierMapper supplierMapper;


    @Override
    public List<zttSupplier> selectAllSupplier() {
        return supplierMapper.selectAllSupplier();
    }

    @Override
    public void insertSupplier(zttSupplier supplier) {
        supplierMapper.insertSupplier(supplier);
    }

    @Override
    public zttSupplier getSupplierByName(zttSupplier supplier) {
        return supplierMapper.getSupplierByName(supplier);
    }


    @Override
    public zttSupplier getSupplierByID(zttSupplier supplier) {
        return supplierMapper.getSupplierByID(supplier);
    }

    @Override
    public void updateSupplier(zttSupplier supplier) {
        if(!Objects.equals(supplier.getSupplierID(), "")){
            zttSupplier supplier1 = supplierMapper.getSupplierByID(supplier);

            if(!Objects.equals(supplier.getSupplierName(), "")){

                supplier1.setSupplierName(supplier.getSupplierName());
            }
            if(!Objects.equals(supplier.getSupplierShortName(), "")){
                supplier1.setSupplierShortName(supplier.getSupplierShortName());
            }
            if(!Objects.equals(supplier.getAddress(), "")){
                supplier1.setAddress(supplier.getAddress());
            }
            if(!Objects.equals(supplier.getCompanyPhone(), "")){
                supplier1.setCompanyPhone(supplier.getCompanyPhone());
            }
            if(!Objects.equals(supplier.getEmail(), "")){
                supplier1.setEmail(supplier.getEmail());
            }
            if(!Objects.equals(supplier.getContactPerson(), "")){
                supplier1.setContactPerson(supplier.getContactPerson());

            }
            if(!Objects.equals(supplier.getContactPhone(), "")){
                supplier1.setContactPhone(supplier.getContactPhone());
            }
            if(!Objects.equals(supplier.getNotes(), "")){
                supplier1.setNotes(supplier.getNotes());
            }
            supplierMapper.updateSupplier(supplier1);
        }
    }

    @Override

    public void deleteSupplier(zttSupplier supplier) {

        supplierMapper.deleteSupplier(supplier);

    }


}
